package com.rchat.pocmini.activity.addfriend;

import com.aso.common.http.delegate.HttpCallbackImpl;
import com.aso.common.http.utils.HttpUtils;
import com.rchat.pocmini.global.HttpCodeGlobal;
import com.rchat.pocmini.global.RequestParam;
import com.rchat.pocmini.global.UrlsGlobal;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by ljd on 2017/8/7.
 */

public class AddFriendModelImpl implements AddFriendContract.Model {

    @Override
    public void searchUser(String phone, String displayName, String account, HttpCallbackImpl callback) {
        //TODO 优化：后台是分别取值查三个数据，其实是可以统一一个参数，查三个数据的，因为客户端只有一个输入框，三个字段为同一个值为冗余
        Map<String, String> param = new HashMap<>();
        param.put("phone", phone);
        param.put("account", account);
        param.put("displayName", displayName);
        //body = {"code":1035,,"data":{"platform":1,"version":"1.0","enterprise":1"phone":"0707","account":"0707","displayName":"0707"}}
        String body = RequestParam.requestRootParam(HttpCodeGlobal.REQ_CODE_1035, param);
        HttpUtils.postAsyn(UrlsGlobal.getUrl(UrlsGlobal.QUERY_FRIEND), body, callback);
    }

    @Override
    public void scanUser(String userName, HttpCallbackImpl callback) {
        //TODO 以上searchUser优化过后可以整合
        Map<String, String> param = new HashMap<>();
        param.put("userName", userName);
        //body = {"code":1230,"data":{"platform":1,"version":"1.0","enterprise":1,"userName":"111110000111"}}
        String body = RequestParam.requestRootParam(HttpCodeGlobal.REQ_CODE_1230, param);
        HttpUtils.postAsyn(UrlsGlobal.getUrl(UrlsGlobal.SCAN_FRIEND), body, callback);
    }

    @Override
    public void addFriend(String userName, String otherName, HttpCallbackImpl callback) {
        Map<String, String> param = new HashMap<>();
        param.put("userName", userName);
        param.put("otherName", otherName);
        //body = {"code":1032,"data":{"platform":1,"version":"1.0","enterprise":1,"otherName":"111110000111","userName":"111110000118"}}
        String body = RequestParam.requestRootParam(HttpCodeGlobal.REQ_CODE_1032, param);
        HttpUtils.postAsyn(UrlsGlobal.getUrl(UrlsGlobal.ADD_FRIEND), body, callback);
    }
}
